//
//  CKTicketVC.m
//  FreshBee
//
//  Created by chenkai on 16/10/18.
//  Copyright © 2016年 iOS013. All rights reserved.
//

#import "CKTicketVC.h"
#import "CKTIcketCell.h"

@interface CKTicketVC ()<UITableViewDelegate,UITableViewDataSource>

@property (weak, nonatomic) IBOutlet UITableView *tableView;


@property (nonatomic,weak)UIAlertController *alertVC;

@end

NSString *reuseId = @"ticketsCell";
@implementation CKTicketVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self.tableView registerNib:[UINib nibWithNibName:@"CKTIcketCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:reuseId];

    self.navItem.title = @"优惠券";
    
    //使用规则:
    UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 80, 20)];
    [btn setTitle:@"使用规则" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(rightNavItemClick) forControlEvents:UIControlEventTouchUpInside];
    [btn.titleLabel setFont:[UIFont systemFontOfSize:14]];
    self.navItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:btn];
    
}

- (void)rightNavItemClick{
    //弹出webView:
    
    CKBaseViewController *webC = [[CKBaseViewController alloc]init];
//    UIWebView *webView = [[UIWebView alloc]initWithFrame:webC.view.bounds];
//    
//    webC.view = webView;
    
    [self.navigationController pushViewController:webC animated:YES];
    
    
    
}

- (IBAction)connectBtnClick:(UIButton *)sender {
    
//    //弹出提示框:
    UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"错误提示!" message:@"请输入正确的优惠券号码" preferredStyle:UIAlertControllerStyleAlert];
    self.alertVC = alertC;
    
    
    [self presentViewController:alertC animated:YES completion:^{
        
        UIView *view = alertC.view.window.subviews.lastObject.subviews.firstObject;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(disMissAlertC:)];
        [view addGestureRecognizer:tap];
        
        NSLog(@"%@",view);
        
    }];
    
    
    
}

- (void)disMissAlertC:(UITapGestureRecognizer *)tap{
    [self.alertVC dismissViewControllerAnimated:YES completion:^{
        [self.tabBarController setNeedsFocusUpdate];
    }];


}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark
#pragma mark 数据源方法:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 10;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    CKTIcketCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseId forIndexPath:indexPath];
    
        [cell changeGrayStyleForRow:indexPath.row];
    
    return cell;
   
}










@end
